package org.xxmi.interview;

import org.junit.Test;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Arrays;

/**
 * Created by XXMI-CY on 2017/8/4.
 */
public class TestInterview {

    /**
     * 跳出多重循环
     * 方法一：
     */
    @Test
    public void test1() {
        System.out.println("开始。。。");
        ok:
        for (int i = 0; i < 10; i++) {
            for (int j = 0; j < 10; j++) {
                System.out.printf("i = %d, j = %d \n", i, j);
                if (j == 5) {
                    break ok;
                }
            }
        }
        System.out.println("结束。。。。");
    }

    /**
     * 跳出多重循环
     * 方式二：
     */
    @Test
    public void test2() {
        System.out.println("开始");
        int arr[][] = {{1, 2, 3}, {4, 5, 6, 7}, {9}};
        boolean found = false;
        for (int i = 0; i < arr.length && !found; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                System.out.printf("i= %d; j=%d \n", i, j);
                if (arr[i][j] == 5) {
                    found = true;
                    break;
                }
            }
        }
        System.out.println("结束");
    }


    /**
     * switch语句能否作用在byte上，能否作用在long上，能否作用在String上?
     */
    @Test
    public void test5() {
//        int sh = 1;   // 可以
//        byte sh = 3;  // 可以
//        short sh = 1; // 可以
//        char sh = 'a';  // 可以
//        long sh = 10;   // 不可以
//        double sh = 1;    // 不可以
//        float sh = 1;   // 不可以
//        switch (sh){
//            case 0:
//                System.out.println("00000");
//                break;
//            case 1:
//                System.out.println("11111");
//                break;
//            default:
//                System.out.println("默认");
//                break;
//        }

        // 字符在1.7可以，1.8 又不行，只能用枚举来解决
//        String sh = "1";
//        switch (sh){
//            case "1":
//                System.out.println("00000");
//                break;
//            case "2":
//                System.out.println("11111");
//                break;
//            default:
//                System.out.println("默认");
//                break;
//        }
    }


    @Test
    public void test6() {
        short s1 = 1;
        short s2 = 1;
//        short s3 = s1+s2;  // 报错
//        s1  = s1+1;   // 报错
        short s4 = 1;
        s4 += 1;
        System.out.println(s4);

        char sex = '男';

        System.out.println(2 << 3);
        BigInteger bigInteger = new BigInteger("100000000000");
        BigInteger bigInteger1 = new BigInteger("2");

        BigInteger multiply = bigInteger.multiply(bigInteger1);
        System.out.println(multiply.toString());
        System.out.println("=================");
        BigDecimal b1 = new BigDecimal("500.000000001");
        BigDecimal b2 = new BigDecimal("500.00");
        int i = b1.abs().compareTo(b2);
        System.out.println(i);
        System.out.println(b1.intValue());
        System.out.println(b1.longValue());
        System.out.println(b1.floatValue());
        System.out.println(b1.doubleValue());


    }

    @Test
    public void test10() {
        final StringBuffer sb = new StringBuffer("sb");
//        sb = new StringBuffer("sb1");
        sb.append("nihao");
        System.out.println(sb.toString());
        sb.delete(0, sb.length());
        System.out.println("删除后：" + sb.toString());

        String a = new String("foo");
        String b = new String("foo");
        System.out.println("a == b ?： " + (a == b));
        System.out.println("a.equals ?：" + a.equals(b));
        int c = 10;
        int d = 10;
        short e = 10;
        System.out.println(c == d);
        System.out.println(c == e);

        String s1 = "abc";
        String s2 = "abc";
        System.out.println("s1 == s2 ? " + (s1 == s2));
        s1 = "aaaa";
        System.out.println(s1);
        System.out.println(s2);
    }

    public void abc() {

    }

    public String abc(int a) {
        return "";
    }

    private void abc(int a, int b) {

    }

    public String abc(String a) {
        return "";
    }


    @Test
    public void test11() {
        String str = "xafdvs";
        char[] arr1 = str.toCharArray();
        char[] arr2 = Arrays.copyOf(arr1, arr1.length);
        for (int i = 0; i < arr1.length - 1; i++) {
            for (int j = i + 1; j < arr2.length; j++) {
                System.out.println(arr1[i] + "," + arr2[j]);
            }
        }
    }
}





































